package picturetaker.application;

import java.sql.SQLException;
import java.util.concurrent.BlockingQueue;

import picturetaker.persistence.ImageManager;
import picturetaker.utility.ApplicationConstants;
import picturetaker.domain.Picture;

public class PersistenceThread implements Runnable, ApplicationConstants {

	private boolean running = true;

	private BlockingQueue<Picture> queue = null;

	private ImageManager manager = null;

	public PersistenceThread(BlockingQueue<Picture> queue) {
		this.queue = queue;
		manager = ImageManager.getInstance();
	}

	public void run() {
		Picture pic = null;
		while (running) {
			try {
				pic = queue.take();			
				manager.insertPicture(pic);
			} catch (InterruptedException e) {
				// Ignore
			} catch (SQLException e) {
				// Ignore
			}

		}
	}
}
